﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RayDen.GLPlayground;
using RayDen.Library.Data.Xml;
using RayDen.Library.Entity.Frames;
using RayDen.Library.Entity.Interface;
using RayDen.RayEngine;

namespace BsdfDevelopment
{
    class App
    {
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

            GlobalConfiguration.Instance.OpenConfig(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Global.Config.xml");
            FrameDescription frame = null;

            string frameName = @"Resources\mat_view_teapot.rdF";
            if (args.Length > 0 && File.Exists(args[0]))
            {
                frameName = args[0];
            }
            using (var frameFile = new FileStream(frameName, FileMode.Open, FileAccess.Read))
            {
                using (var reader = new StreamReader(frameFile))
                    frame = (FrameDescription)SerializationService.Deserialize(reader.ReadToEnd(), typeof(FrameDescription));
            }
            frame.FrameName = Path.GetFileNameWithoutExtension(frameName);
            Console.WriteLine("Frame [[{0}]] loaded, start setuping BsdfRenderer", frame.FrameName);
            var editor = new BsdfEdit();
            IRenderConfig re = new MaterialViewRayEngineConfiguration(editor.ObjectMaterial, editor.PlaneMaterial);
            re.OpenFrame(frame);

            using (var example = new MainWindow(re))
            {
                example.Run(0.25);
            }

        }
    }
}
